home *** CD-ROM | disk | FTP | other *** search
- package asp.netobjects.nfx.wizard;
-
- import asp.netobjects.nfx.util.ExceptionHandler;
- import asp.netobjects.nfx.util.ExternalError;
- import asp.netobjects.nfx.util.InternalError;
- import com.sun.java.swing.JFrame;
- import java.awt.Frame;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Observable;
- import java.util.Observer;
-
- public class Wizard extends Observable implements Observer {
- private WizardView dmWizardView;
- private ExceptionHandler dmExceptionHandler;
- private Hashtable dmPageIndex;
- private String dmCodeBase;
- private WizardPage dmCurrPage;
- private boolean dmOk = true;
-
- public Wizard(Frame parent, String title, String codeBase, ExceptionHandler handler) {
- this.dmExceptionHandler = handler;
- this.dmCodeBase = codeBase;
- this.dmPageIndex = new Hashtable();
- this.dmWizardView = new WizardView(this, parent, title);
- }
-
- public Wizard(JFrame parent, String title, String codeBase, int width, int height, ExceptionHandler handler) {
- this.dmExceptionHandler = handler;
- this.dmCodeBase = codeBase;
- this.dmPageIndex = new Hashtable();
- this.dmWizardView = new WizardView(this, parent, title, width, height);
- }
-
- public ExceptionHandler getExceptionHandler() {
- return this.dmExceptionHandler;
- }
-
- public void setExceptionHandler(ExceptionHandler handler) {
- this.dmExceptionHandler = handler;
- }
-
- public String getCodeBase() {
- return this.dmCodeBase;
- }
-
- public Hashtable getPageIndex() {
- return this.dmPageIndex;
- }
-
- public WizardView getView() {
- return this.dmWizardView;
- }
-
- public WizardPage getCurrPage() {
- return this.dmCurrPage;
- }
-
- public void setVisible(boolean set) {
- this.dmWizardView.setVisible(set);
- }
-
- public boolean isOk() {
- return this.dmOk;
- }
-
- public void setOk(boolean set) {
- this.dmOk = set;
- }
-
- public void initialize() throws InternalError, ExternalError {
- this.dmWizardView.initialize();
- WizardPage firstPage = (WizardPage)this.getPageIndex().get(Integer.toString(1));
- this.dmCurrPage = firstPage;
- }
-
- public void destroy() {
- ((Observable)this).deleteObservers();
- Enumeration e = this.dmPageIndex.elements();
-
- while(e.hasMoreElements()) {
- WizardPage p = (WizardPage)e.nextElement();
- ((Observable)p).deleteObservers();
- this.dmWizardView.removePageView(p.getView());
- p.destroy();
- }
-
- this.dmPageIndex.clear();
- }
-
- public void finish() throws InternalError, ExternalError {
- }
-
- public final void nextPage() throws InternalError, ExternalError {
- this.dmCurrPage.validate();
- this.dmCurrPage.commit();
- this.dmCurrPage = this.getNext(this.dmCurrPage);
- if (this.dmCurrPage.getView() == null) {
- this.dmCurrPage.createView();
- this.add(this.dmCurrPage);
- this.dmWizardView.addPageView(String.valueOf(this.dmCurrPage.getId()), this.dmCurrPage.getView());
- }
-
- this.dmCurrPage.initialize(1);
- this.dmWizardView.showPageView(String.valueOf(this.dmCurrPage.getId()));
- this.enableButtons();
- }
-
- public final void previousPage() throws InternalError, ExternalError {
- this.dmCurrPage = this.getPrevious(this.dmCurrPage);
- if (this.dmCurrPage.getView() == null) {
- this.dmCurrPage.createView();
- this.add(this.dmCurrPage);
- this.dmWizardView.addPageView(String.valueOf(this.dmCurrPage.getId()), this.dmCurrPage.getView());
- }
-
- this.dmCurrPage.initialize(2);
- this.dmWizardView.showPageView(String.valueOf(this.dmCurrPage.getId()));
- this.enableButtons();
- }
-
- public WizardPage getNext(WizardPage page) throws InternalError, ExternalError {
- return page.getNext();
- }
-
- public WizardPage getPrevious(WizardPage page) throws InternalError, ExternalError {
- return page.getPrevious();
- }
-
- public WizardPage getFinal(WizardPage page) throws InternalError, ExternalError {
- return page.getFinal();
- }
-
- public void add(WizardPage page) throws InternalError {
- page.setId(this.dmPageIndex.size() + 1);
- ((Observable)page).addObserver(this);
- Enumeration e = this.dmPageIndex.elements();
-
- while(e.hasMoreElements()) {
- WizardPage p = (WizardPage)e.nextElement();
- ((Observable)p).addObserver(page);
- ((Observable)page).addObserver(p);
- }
-
- this.dmPageIndex.put(String.valueOf(page.getId()), page);
- if (this.dmPageIndex.size() == 1) {
- this.dmCurrPage = page;
- this.dmCurrPage.createView();
- this.dmWizardView.addPageView(String.valueOf(this.dmCurrPage.getId()), this.dmCurrPage.getView());
- }
-
- }
-
- public void enableButtons() {
- boolean prev = false;
- boolean valid = false;
-
- try {
- prev = this.dmCurrPage.getPrevious() != null;
- valid = this.dmCurrPage.isValid();
- } catch (Throwable var3) {
- }
-
- if (prev) {
- this.dmWizardView.enablePrevious(true);
- } else {
- this.dmWizardView.enablePrevious(false);
- }
-
- if (valid && !this.dmCurrPage.isLastPage()) {
- this.dmWizardView.enableNext(true);
- } else {
- this.dmWizardView.enableNext(false);
- }
-
- if (!valid || !this.dmCurrPage.isLastPage() && !this.dmCurrPage.canFinish()) {
- this.dmWizardView.enableFinish(false);
- } else {
- this.dmWizardView.enableFinish(true);
- }
-
- }
-
- public void update(Observable observable, Object object) {
- }
- }
-